<?php
/**
 * $Id$
 * 
 * This file can not be redistributed to anyone without the permission of Giga Promoters
 * Copyright 2005 - 2008, Giga Promoters
 * 						  608 Aggarwal Cyber Plaza
 *						  Netaji Subhash Place, Delhi - 110034
 *						  www.gigapromoters.com
 * 
 *
 * @version 			$Rev$
 * @lastModifiedBy		$LastChangedBy$
 * @lastChanged			$Date$
 * @copyright 			Giga Promoters (www.gigapromoters.com)
 * 
 */

define('THEME_DIR', WWW_ROOT.'themed'.DS);

/**
 * Set themed view and theme name from this hook
 *
 * @param unknown_type $controller
 */
function ThemesbeforeFilterhook(&$controller)
{
	//Initialization shifted to InitHook.
	/*$themes = getThemes();
	if(Configure::read('cmsConfig.Theme.allowUserTheme')==1)
	{
		if(isset($_COOKIE['user_theme']) && in_array($_COOKIE['user_theme'],$themes))
		{
			Configure::write('cmsConfig.Theme.name',$_COOKIE['user_theme']);
		}
	}
	//prd(Configure::read('cmsConfig.Theme.name'));
	
	if(cr('ThemeConfig.name'))
	{
		$controller->theme = cr('ThemeConfig.name');
	}
	//pr($controller->theme);
	if(isset($controller->params['prefix']) && $controller->params['prefix'] =='admin')
	{
		//$controller->view = 'Theme'; 
		if(Configure::read('cmsConfig.Theme.adminTheme'))
		{
			//$controller->view = 'Theme'; 
			//$controller->theme = Configure::read('cmsConfig.Theme.adminTheme');
		}
	}*/
}

function ThemesBuildAdminMenuHook($backend)
{
	$backend->addMenuItem(ADMIN_APPEARANCE, __('Themes'),"/themes/themes/index");
}

function ThemesAfterComponentInitHook($controller)
{
	if(cr('cmsInstalled') && @strpos($_SERVER['REQUEST_URI'],'/cms/startTestSession') === false)
	{
		Configure::registerConfigModelLoder("ThemeConfig",'Themes.ThemeConfig');
		$themeFilePath = WWW_ROOT.'themed'.DS.cr('ThemeConfig.name').DS.'theme_config.php';
		if(file_exists($themeFilePath))
		{
			require_once($themeFilePath);
		}
		$themes = getThemes();
		if(Configure::read('cmsConfig.Theme.allowUserTheme')==1)
		{
			if(isset($_COOKIE['user_theme']) && in_array($_COOKIE['user_theme'],$themes))
			{
				Configure::write('cmsConfig.Theme.name',$_COOKIE['user_theme']);
			}
		}
		//prd(Configure::read('cmsConfig.Theme.name'));
		
		if(cr('ThemeConfig.name'))
		{
			$controller->theme = cr('ThemeConfig.name');
		}
		//pr($controller->theme);
		if(isset($controller->params['prefix']) && $controller->params['prefix'] =='admin')
		{
			//$controller->view = 'Theme'; 
			if(Configure::read('cmsConfig.Theme.adminTheme'))
			{
				//$controller->view = 'Theme'; 
				//$controller->theme = Configure::read('cmsConfig.Theme.adminTheme');
			}
		}
	}	
}


?>